#!/bin/bash
HOST=$1
USER=$2
PASS=$3
DATABASE=$4
COMMAND=$5

[[ $# != 5 ]] && echo "Error: Usage $0 HOST USER PASS DATABASE 'COMMAND;'" && exit 1

mysql -h$HOST -u$USER -D$DATABASE -p$PASS -e "exit"
[[ $? != 0 ]] && echo "登陆失败" && exit 1
mysql -h$HOST -u$USER -D$DATABASE -p$PASS -e "$COMMAND"